package com.whity.towerdefense.view;

import java.util.HashMap;

import javax.microedition.khronos.opengles.GL10;

import com.whity.towerdefense.Utils;

import android.graphics.Bitmap;
import android.util.Log;

public class GraphicEltFactory
{
	// =============================================================
	// Private attributs :
	
	private static final String							TAG = "cm.djm.test03.view";
	
	private static final HashMap<String, GraphicHeart>	m_GraphicHearts = new HashMap<String, GraphicHeart>();
	
	// =============================================================
	// Protected attributs ;
	
	protected static Bitmap 							ERROR_IMAGE;
	
	// =============================================================
	// Public functions :
	
	public GraphicEltFactory()
	{
	}
	
	public static GraphicElt CreateGraphicElt(String p_Path)
	{
		// If the graphic heart isn't already created , we create it
		GraphicHeart grphHrt;
		if((grphHrt = m_GraphicHearts.get(p_Path)) == null)
		{
			try
			{
				grphHrt = new GraphicHeart(Utils.GRAPHICS_PATH + p_Path);
			} catch (Exception e)
			{
				Log.e(TAG, "Can't create graphic heart : " + p_Path);
				System.exit(-3);
			}
			m_GraphicHearts.put(p_Path, grphHrt);
			return new GraphicElt(grphHrt);
		}
		else
		{
			return new GraphicElt(grphHrt);
		}
	}
	
	public static void LoadGraphism(GL10 p_GL)
	{
		for(GraphicHeart elt : m_GraphicHearts.values())
		{
			elt.LoadGraphism(p_GL);
		}
	}
	
	public static void UnloadGraphism(GL10 p_GL)
	{
		for(GraphicHeart elt : m_GraphicHearts.values())
		{
			elt.UnloadGraphism(p_GL);
		}
	}
	
	public static GraphicHeart GetGraphicHeart(String p_Path)
	{
		GraphicHeart grphHrt;
		if((grphHrt = m_GraphicHearts.get(p_Path)) == null)
		{
			try
			{
				grphHrt = new GraphicHeart(Utils.GRAPHICS_PATH + p_Path);
			} catch (Exception e)
			{
				Log.e(TAG, "Can't create graphic heart : " + p_Path);
				System.exit(-3);
			}
			return grphHrt;
		}
		else
		{
			return grphHrt;
		}
	}
	
	// =============================================================

}
